Repository navigation
[PIR #1911] Windows: never run a program from the current folder - #1948
Merged
Merged
Conversation
…ev entry point Windows looks a bare program name up in the current folder before PATH, so a git.exe committed to a repository would run under Codev. A side-effect module sets the variable before anything can spawn; a guard test enforces it is the first import of every bin and both server entries, and a Windows test plants a git.exe and proves it never runs.
… PATH The extension host is shared, so it cannot set the variable process-wide. An unresolved bare name now fails with ENOENT instead of reaching spawn, where Windows would search the workspace folder.
… to platform/windows/exe-search.ts
…ilder not-found message, nits, .NET note
amrmelsayed
added a commit
that referenced
this pull request
Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PIR Review: Windows never runs a program from the current folder
Fixes #1911
Summary
On Windows, a program started by bare name (
git,gh,npm,codev) is looked up in the current folder beforePATH, so agit.execommitted to a repository ran in place of Git whenever Codev rangitthere. Every Codev process now importslib/process-bootstrap.tsfirst, which on Windows setsNoDefaultCurrentDirectoryInExePath=1(lib/platform/windows/exe-search.ts); libuv andcmd.exeboth honor it, and everything Codev starts inherits it, including every terminal Tower opens. With the hole closed, the native-Windows "preview" wording is removed from the README and bothDEPENDENCIES.mdcopies.What is covered:
codev,afx,porch,consult,team,generate-image), the Tower server and shellper. A guard test fails if a new command does not import the bootstrap first.child_processspawns andexecSyncstrings throughcmd.exe).windowsPtyBaseEnvallowlist, which now sets the variable explicitly.cli-process.tsrefuses acodev/afx/porchname that does not resolve onPATH, rather than letting Windows find a same-named file in the workspace. Spawn Builder then shows "afx was not found on PATH" instead of an unhandled error.User-visible change (
cmd.exe): in acmd.exesession inside a Codev terminal, a program in the current folder no longer runs by bare name;.\namestill runs it. PowerShell, the default Windows shell, already works this way. Verified on the host:cmd.exeruns a plantedgit.exeby default, the real Git with the variable set, and the planted file again as.\git.Known effect on other tools: a .NET 10 NativeAOT
dotnet publishfails inside a Codev terminal, because Visual Studio'svcvarsall.batdoes not support the setting (dotnet/runtime#129340, closed as fixed in .NET 11; confirmed by reading the issue, not reproduced here). Documented inDEPENDENCIES.md; nothing else is done about it.Not changed: node-pty does its own
PATH-only lookup and never searches the terminal's folder, so the PTY launch path needed nothing (measured: a bare unresolvable name fails with "File not found"). A relative.entry in the user's ownPATHis still searched; that is the user's configuration.Files Changed
README.md(+1 / -1)apps/vscode/src/__tests__/cli-process.test.ts(+44 / -2)apps/vscode/src/__tests__/spawn-builder-not-found.test.ts(new)apps/vscode/src/cli-process.ts(+34 / -2)apps/vscode/src/commands/spawn.ts('error' listener)codev-skeleton/DEPENDENCIES.md(+8 / -7)codev/DEPENDENCIES.md(+8 / -7)codev/plans/1911-windows-bare-name-user-tool-sp.md(+147 / -0)codev/resources/arch.md(Platform Layer: process bootstrap)codev/resources/lessons-learned.md(Testing: two lessons)codev/reviews/1911-windows-bare-name-user-tool-sp.md(this file)codev/state/pir-1911_thread.md(+30 / -0)packages/codev/bin/afx.js(+2 / -0)packages/codev/bin/codev.js(+2 / -0)packages/codev/bin/consult.js(+2 / -0)packages/codev/bin/generate-image.js(+2 / -0)packages/codev/bin/porch.js(+2 / -0)packages/codev/bin/team.js(+2 / -0)packages/codev/src/__tests__/process-bootstrap.test.ts(+80 / -0)packages/codev/src/__tests__/shell-launch.test.ts(one assertion)packages/codev/src/__tests__/tower-lifecycle.windows.test.ts(+61 / -0)packages/codev/src/__tests__/windows-exe-search.test.ts(+83 / -0)packages/codev/src/agent-farm/servers/tower-server.ts(+2 / -0)packages/codev/src/lib/platform/windows/exe-search.ts(+25 / -0)packages/codev/src/lib/platform/windows/pty-env.ts(sets the variable in the fallback allowlist)packages/codev/src/lib/process-bootstrap.ts(+24 / -0)packages/codev/src/terminal/shellper-main.ts(+2 / -0)Commits
e145f3cb9[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Terminal coverage test: end every recorded session in teardowndb8577b67[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Thread: checks pass, back at dev-approval53a1f3cba[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Cover every Tower terminal: test it, correct the docs663603ee9[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Thread: checks pass, at dev-approvalf9d0c8b26[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Thread: Node 22 runs, waiting on Windows: bugfix-1814 check-timeout test fails under full-suite load; its 2500ms bound cannot tell a late kill from no kill #19463bef42211[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Rename to lib/process-bootstrap.ts; move the Windows step to platform/windows/exe-search.ts1cfb06b92[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Thread: implement notes1b16aeecd[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Docs: native Windows is no longer a preview4d54ae89e[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] VS Code: refuse a Codev CLI name that does not resolve on PATH7d4d41f74[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Set NoDefaultCurrentDirectoryInExePath first in every Codev entry point20606082b[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Plan revised: set NoDefaultCurrentDirectoryInExePath at entry pointsb5865fe9f[PIR Windows: bare-name user-tool spawns resolve in the cwd before PATH; turn off the current-folder lookup at process start (release blocker, removes the native-Windows preview) #1911] Plan draft(Plus a merge of
mainfor #1947 and porch's ownchore(porch)commits.)Test Results
npm run build: ✓ passnpm test(porchtestscheck, run alone on the host): ✓ pass. A direct run of the same suite after themainmerge: 8123 passed, 247 skipped, plus the two tests: load-dependent failures in the packages/codev suite on a native Windows dev machine (agy-auth-cache EPERM, metrics-model-id barrier, windows-job census, worker exit) #1923 flakes below, which pass on their own.process-bootstrap.test.ts: the bootstrap sets the variable onwin32only; everybin/command and both server entries import it first.windows-exe-search.test.ts(Windows): plants a copy ofhostname.exeasgit.exe. Control: with the variable removed,gitruns the planted file. Hardened:execFileSync,spawnSyncand anexecSyncstring all run the real Git. With Git offPATH: ENOENT, and the planted file still never runs.tower-lifecycle.windows.test.ts, new scenario: an isolated Tower started WITHOUT the variable opens a persistent builder terminal, a persistent API shell terminal and the dashboard's PowerShell shell tab; all three carryNoDefaultCurrentDirectoryInExePath=1. With the bootstrap import removed fromafx, Tower and shellper, it fails (unset). Its teardown ends every session the test Tower recorded, pass or fail.cli-process.test.ts: an unresolved bare name on Windows is never spawned and fails as ENOENT; a resolved one still spawns.spawn-builder-not-found.test.ts: Spawn Builder turns that ENOENT into "afx was not found on PATH".shell-launch.test.ts:windowsPtyBaseEnvsets the variable even when the parent did not.porch initin a repository containing a plantedgit.exe. Without the bootstrap the planted file ran (Command failed: git add, no commit); with it, the real Git made the commit.windows.yml): https://github.com/cluesmith/codev/actions/runs/45082298979 on the final commit (consultation fixes,199c344d6+ porch state). Earlier green runs: 45080898387 (e145f3cb9), 45079432385 (53a1f3cba), 45078247361, 44725012668.npm run buildpass;npm test8127 passed, 247 skipped, 0 failed; VS Codecli-process+ Spawn Builder tests pass. No shellper left running afterwards.Architecture Updates
Routed to COLD
codev/resources/arch.md, Platform Layer: a "Process bootstrap and current-folder lookup" bullet (every entry point importslib/process-bootstrap.tsfirst; on Windows it setsNoDefaultCurrentDirectoryInExePath; children and every Tower terminal inherit it; the VS Code host refuses unresolved names instead). Not HOT: it changes behavior on one platform and is enforced by a guard test, so it does not need to be in every prompt.Lessons Learned Updates
Routed to COLD
codev/resources/lessons-learned.md, Testing:{ ...process.env }copy has case-sensitive keys, so deletingNoDefaultCurrentDirectoryInExePathmissed the inheritedNODEFAULTCURRENTDIRECTORYINEXEPATH.tower stop, so a test that opens them must end every session its Tower recorded, infinally, and confirm with a before/after process count.Things to Look At During PR Review
agyCLI was not found on this host; porch recorded the skip as COMMENT). Acted on, with the architect's go-ahead: Claude found that the non-persistent fallback'swindowsPtyBaseEnvallowlist lacked the variable, so a builder terminal created while shellper is unavailable kept the Windows default, contradicting "every terminal" in the docs (architect and shell-tab fallbacks pass Tower's full env and were covered). Fixed inpty-env.tswith a unit assertion. Also from Claude: Spawn Builder had no'error'listener, now shows "afx was not found on PATH"; nits (errno comment, the hand-listedSERVER_ENTRY_POINTScomment, a null check in the new scenario). Codex's .NET NativeAOT note was checked against NativeAOT publish fails at link step when NoDefaultCurrentDirectoryInExePath is set dotnet/runtime#129340 and documented.windowsPtyBaseEnvallowlist and would keep the Windows default. That was wrong: only the non-persistent fallback uses the allowlist (and it now sets the variable too); persistent terminals (architect, builder, shell tab) are built from Tower's environment. The owner chose to keep every terminal covered. Docs and plan now say so.cmd.exebehavior change above is the one user-visible effect. PowerShell is unaffected.process-bootstrap.test.tschecks the first statement of eachbin/*.jsand both server entries; the bootstrap andexe-search.tsimport nothing.afxwould inherit the variable anyway; the direct imports cover a Tower or shellper started some other way.apps/vscode/src/cli-process.ts) returns aChildProcessthat emits an ENOENT-shaped error on the next tick (andexecCodevClirejects) when the resolver hands back an unresolved bare name. Callers already handle spawn errors.commandExistsunification were deliberately left out of this PR (the plan's first draft proposed converting ~70 sites). With the variable set process-wide they are no longer needed to close the hole; they can be a follow-up if wanted.How to Test Locally
afx dev pir-1911npx vitest run src/__tests__/windows-exe-search.test.ts src/__tests__/process-bootstrap.test.tsinpackages/codev.npx vitest run src/__tests__/tower-lifecycle.windows.test.ts -t 1911(isolated Tower; leaves no shellpers behind).C:\Windows\System32\hostname.exetogit.exe, then run a Codev command that runsgitthere (e.g.porch init); the real Git runs.cmd.exeterminal:set NoDefaultCurrentDirectoryInExePathprints1; a program in the folder runs only as.\name.env -u NoDefaultCurrentDirectoryInExePathin Git Bash), since Claude Code's shell already exports it.Flaky Tests (if any)
All are recorded on #1923; each was left running, not skipped, and passed on its own or on re-run:
packages/codev/src/commands/porch/__tests__/bugfix-1814-check-timeout.test.ts("a protocol.json timeout_ms reaches the runner and kills the check at that value"): 2574–3271 ms against a 2500 ms bound under load; blocked porch twice. Fixed onmainby Fix #1946: check-timeout tests tell a late Windows kill from no kill #1947 (Windows: bugfix-1814 check-timeout test fails under full-suite load; its 2500ms bound cannot tell a late kill from no kill #1946) and merged into this branch.packages/codev/src/agent-farm/__tests__/launch-loop-exit-code.test.ts:49("still auto-restarts after a crash"): EBUSY / EPERM removing its temp folder inafterEach.packages/codev/src/__tests__/tower-lifecycle.windows.test.ts, scenario 4 ("a session survives tower stop/start", agent pid not alive after restart, under full-suite load) and scenario 5 (read ECONNRESETon Windows CI Node 22, run 44725012668; also failed on another branch before this change).